<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
	<style>
		.form {
			width: 600px;
			margin: 100px auto;
		}

		.item {
			padding: 8px 8px;
		}

		/* 匹配后代元素聚焦 */
		.item:focus-within {
			background-color: rgb(198, 211, 255);
		}

		/* 匹配兄弟元素是否有required属性 */
		label:has(+input[required]):after {
			content: '*';
			color: red;
		}
	</style>
</head>

<body>
	<div class="form">
		<div class="item">
			<label>账号</label>
			<input type="text">
		</div>
		<div class="item">
			<label>密码</label>
			<input required type="text">
		</div>
	</div>
</body>

</html>